<%@page contentType="text/html" pageEncoding="UTF-8" import="java.util.*, Modelo.*, javax.swing.*" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">

<%
//esto es para que no guarde en el cache la pagina
            response.setHeader("Cache-Control", "max-age=0");
            response.setHeader("Cache-Control", "no-cache");
            response.setHeader("Cache-Control", "no-store");
            response.setHeader("Pragma", "no-cache");
            response.setDateHeader("Expires", -1);
%>
<html>
    <head>
        <title>Autoevaluacion</title>
        <link href="<%=request.getContextPath()%>/css/style.css" rel="stylesheet" type="text/css" media="screen" />
        <script type="text/javascript" src="<%=request.getContextPath()%>/jQuery/js/jquery-1.3.2.min.js"></script>
        <script type="text/javascript" src="<%=request.getContextPath()%>/jQuery/js/jquery-ui-1.7.2.custom.min.js"></script>
       <link type="text/css" href="<%=request.getContextPath()%>/jQuery/css/custom-theme/jquery-ui-1.8.4.custom.css" rel="Stylesheet" />
        <style type="text/css" title="currentStyle">
            @import "<%=request.getContextPath()%>/jQuery/DataTables-1.7.1/media/css/demo_page.css";
            @import "<%=request.getContextPath()%>/jQuery/DataTables-1.7.1/media/css/demo_table_jui.css";
            @import "<%=request.getContextPath()%>/jQuery/DataTables-1.7.1/examples/examples_support/themes/smoothness/jquery-ui-1.7.2.custom.css";
        </style>
        <script type="text/javascript" language="javascript" src="<%=request.getContextPath()%>/jQuery/DataTables-1.7.1/media/js/jquery.js"></script>
        <script type="text/javascript" language="javascript" src="<%=request.getContextPath()%>/jQuery/DataTables-1.7.1/media/js/jquery.dataTables.js"></script>
        <script type="text/javascript" charset="utf-8">
            $(document).ready(function() {
                oTable = $('#example').dataTable({
                    "bJQueryUI": true,
                    "sPaginationType": "full_numbers"
                });
            } );
        </script>



    </head>

    <body>
        <%
                    HttpSession s = request.getSession();
                    Persona persona = new Persona();
                    if (s.getAttribute("logged") != null && s.getAttribute("logged").equals(true)) {
                        if (s.getAttribute("persona") != null) {
                            persona = (Persona) s.getAttribute("persona");
                            //JOptionPane.showMessageDialog(null,persona.getId());
                        } else {
                            //JOptionPane.showMessageDialog(null, "mala");
                        }
        %>


        <div >
            <%

                                    Encuesta e = new Encuesta();
                                    P_E_F pef1 = new P_E_F();
                                    List l = pef1.fndAllPetsByName("SELECT P_E_F.* FROM P_E_F"
                                            + " INNER JOIN PROYECTO ON P_E_F.`PROYECTO_ID` = PROYECTO.`ID`"
                                            + " INNER JOIN ENCUESTA ON P_E_F.`ENCUESTA_ID` = ENCUESTA.`ID`"
                                            + " INNER JOIN MUESTRA ON PROYECTO.`ID` = MUESTRA.`PROYECTO_ID`"
                                            + " WHERE MUESTRA.`PERSONA_Cedula` = " + persona.getId()
                                            + " AND P_E_F.`FUENTE_ID` = " + persona.getFuente().getId()
                                            + " AND P_E_F.`ENCUESTA_ID`"
                                            + " NOT IN (Select ALL r.IDENCUESTA from r WHERE r.IDPERSONA = " + persona.getId()
                                            + " AND  EXISTS (Select All ENCUESTA.`ID` from ENCUESTA where r.IDENCUESTA=ENCUESTA.ID))");
                                    Iterator it = l.iterator();
                                    if (l.size() == 0) {%>
            <h3>No Existen Encuestas Disponibles</h3>
            <%} else {%>
            <h3>Encuestas Disponibles</h3>
            <!-- tabla-->
            <table cellpadding="0" cellspacing="0" border="0" class="display" id="example">
                <thead>
                    <tr>
                        <th>Encuesta</th>
                        <th>descripcion</th>
                        <th></th>
                    </tr>
                </thead>
                <tbody>

                    <%

                                                            while (it.hasNext()) {
                                                                //    JOptionPane.showMessageDialog(null, it.next());

                                                                pef1 = (P_E_F) it.next();
                                                                e = pef1.getEncuesta();
                    %>
                    <tr>
                        <td><%=e.getNombre()%></td>
                        <td><%=e.getDescripcion()%></td>
                        <td>  <a href="<%=request.getContextPath() + "/fuente/encuesta.jsp?iden=" + e.getId() + "&idpro=" + pef1.getProyecto().getId()%>" title="Encuesta"> Ver</a>&nbsp;
                    </tr>

                    <%
                                                }

                                            }

                    %>
                </tbody>
            </table>
        </div>


     

        <%} else {
                        response.sendRedirect(request.getContextPath() + "/index.jsp");
                    }%>
    </body>
</html>
